/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:SecureBox.UI"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"

  You can also use Blend to do all this with the tool's support.
  See http://www.galasoft.ch/mvvm
*/

using System;
using System.Windows;
using PhoneCore.Framework;
using PhoneCore.Framework.Bootstrap;
using PhoneCore.Framework.IoC;
using PhoneCore.Framework.Navigation;
using PhoneCore.Framework.Views;
using SecureBox.UI.Infrastructure;

namespace SecureBox.UI.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public class ViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
        }
        
        private IPageMapping _pageMapping;
        protected IPageMapping PageMapping
        {
            get
            {
                if(_pageMapping == null)
                {
                    var bootstrapper = Application.Current.Resources["Bootstrapper"] as ApplicationBootstrapper;
                    IContainer container = bootstrapper.GetContainer();
                    _pageMapping = container.Resolve<IPageMapping>();
                }

                return _pageMapping;
            }
            
    
        }

        #region ViewModel properties
        /// <summary>
        /// Gets the Startup property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Startup
        {
            get
            {
                return PageMapping.GetViewModel("Startup");
            }
        }

        /// <summary>
        /// Gets the Library property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Library
        {
            get
            {
                return PageMapping.GetViewModel("Library");
            }
        }

        /// <summary>
        /// Gets the Password property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Password
        {
            get
            {
                return PageMapping.GetViewModel("Password");
            }
        }


        /// <summary>
        /// Gets the Account property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Account
        {
            get
            {
                return PageMapping.GetViewModel("Account");
            }
        }

        /// <summary>
        /// Gets the Email property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Email
        {
            get
            {
                return PageMapping.GetViewModel("Email");
            }
        }

        /// <summary>
        /// Gets the Note property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Note
        {
            get
            {
                return PageMapping.GetViewModel("Note");
            }
        }

        /// <summary>
        /// Gets the Search property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Search
        {
            get
            {
                return PageMapping.GetViewModel("Search");
            }
        }

        /// <summary>
        /// Gets the Settings property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Settings
        {
            get
            {
                return PageMapping.GetViewModel("Settings");
            }
        }

        /// <summary>
        /// Gets the Settings property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IViewModel Health
        {
            get
            {
                return PageMapping.GetViewModel("Health");
            }
        }

        #endregion
    }
}